package com.hand.demo.app.service.impl;

import org.hzero.boot.scheduler.infra.annotation.JobHandler;
import org.hzero.boot.scheduler.infra.enums.ReturnT;
import org.hzero.boot.scheduler.infra.handler.IJobHandler;
import org.hzero.boot.scheduler.infra.tool.SchedulerTool;
import java.util.Map;


@JobHandler("xzy_handler")
public class XzyJobHandler implements IJobHandler {
    @Override
    public ReturnT execute(Map<String, String> map, SchedulerTool tool) {
        try{
            Thread.sleep(1000);
        }catch (InterruptedException e){
            Thread.currentThread().interrupt();
        }
        // 刷新任务进度及描述
        tool.updateProgress(100, "牢大的任务执行中。。。");
        // 任务日志记录
        tool.info("树脂666，租户ID为：" + tool.getBelongTenantId());
        return ReturnT.SUCCESS;
    }

    @Override
    public void onCreate(SchedulerTool tool) {
        tool.info("执行任务前初始化数据。。。");
        IJobHandler.super.onCreate(tool);
    }

    @Override
    public void onException(SchedulerTool tool) {
        tool.info("任务出现错误。。。");
        IJobHandler.super.onException(tool);
    }

    @Override
    public void onFinish(SchedulerTool tool, ReturnT returnT) {
        tool.info("任务结束。。。");
        IJobHandler.super.onFinish(tool, returnT);
    }
}
